/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.leetCode;

import java.util.HashMap;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/5/7
 */
public class _7_1_TwoSum {

    public int[] twoSum(int[] nums, int target) {
        int len = nums.length;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < len; ++i) {
            if (map.containsKey(nums[i])) {
                return new int[]{map.get(nums[i]), i};
            }
            map.put(target - nums[i], i);
        }
        throw new IllegalArgumentException("No two sum solution");
    }

    public static void main(String[] args) {
        Utils.printArray(new _7_1_TwoSum().twoSum(new int[]{2, 7, 11, 15}, 9));
        Utils.printArray(new _7_1_TwoSum().twoSum(new int[]{0, 4, 3, 0}, 0));
    }
}
